import { Injectable } from '@nestjs/common';
import { Logger } from 'nestjs-pino';

@Injectable()
export class LoggerService extends Logger {
  /**
   * 记录HTTP请求错误
   * @param errorMessage 错误消息
   * @param url 请求URL
   * @param code 错误码
   */
  logHttpRequestError(errorMessage: string, url: string, code: string): void {
    console.log(errorMessage, url, code, 333333);
    this.error('HTTP请求错误', errorMessage, 'HTTP', {
      request: {
        url,
        code,
      },
    });
  }

  /**
   * 记录业务逻辑错误
   * @param errorCode 错误码
   * @param errorMessage 错误消息
   * @param businessContext 业务上下文
   * @param error 错误对象
   */
  logBusinessError(
    errorCode: string,
    errorMessage: string,
    businessContext: string,
    error?: Error,
  ): void {
    this.error(errorMessage, error, 'BUSINESS', {
      errorCode,
      businessContext,
    });
  }
}
